<?php

namespace app\api\controller;

use app\api\logic\AgreementLogic;
use app\common\controller\Api;
use think\Validate;

class Agreement extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    public function list()
    {
        $logic = new AgreementLogic();
        $data = $logic->getList();

        return $this->success('success', $data);
    }

    public function detail()
    {
        $param = [
            'id' => $this->request->get('id'),
        ];

        $rule = [
            'id' => 'require|integer',
        ];

        $msg = [
            'id.require' => 'id不能为空',
            'id.integer' => 'id必须为整数',
        ];

        $validate = new Validate($rule, $msg);
        $result = $validate->check($param);
        if (!$result) {
            return $this->error($validate->getError());
        }

        $logic = new AgreementLogic();
        $data = $logic->detail($param['id']);

        return $this->success('success', $data);
    }
}